<template>
	<view class="xilu">
		<view class="container plr20">
			<view class="pb30">
				<template v-if="list.length > 0">
					<view class="xilu_item flex-row" v-for="(vo, keys) in list" :key="vo.id"
						@click="toOrderDetail(vo.id)">
						<!-- 左侧头像 -->
						<image class="avatar" :src="vo.order_detail.xilufitness_urls.wares_image" mode="aspectFill"></image>
						<!-- 右侧内容 -->
						<view class="right-content flex-col flex-grow-1">
							<view class="title fs32  lh44 col3">{{ vo.pay_body || '' }}</view>
							<view class="subtitle mt10 fs28 col9 lh40">
								{{ vo.pay_time || '' }}
							</view>
							<view class="status-express mt6">
								<text class="status" :class="vo.status == '已支付' ? 'paid' : 'unpaid'">
									{{ vo.status || '' }}
								</text>
								
								<text class="express ml20" v-if="vo.status == 2 || vo.status == 3 || vo.status == 4">
									快递单号：{{ vo.ship_num }}
								</text>
							</view>
							<view class="pay-info mt20">
								<text class="pay-type yellow">
									{{ vo.pay_type || '' }}：
								</text>
								<text class="pay-amount yellow">{{ vo.total_amount || 0 }}</text>
							</view>
							<view class="pay-info mt20" v-if="vo.ebb_status != 0">
								<text class="pay-type yellow">
									{{ vo.ebb || '' }}
								</text>
							</view>
						</view>
						<!-- 右下角箭头 -->
						<view class="arrow-box">
							<text class="arrow-icon">›</text>
						</view>
					</view>
				</template>

				<template v-else>
					<button @click="getList()" class="col3">刷新数据</button>
					<empty-data :tips="'暂无订单数据'" :lineHeight="150"></empty-data>
				</template>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				total_count: 0,
				pay_type: '',
				// 替换成你的默认头像地址
				defaultAvatar: 'https://img.yzcdn.cn/vant/cat.jpeg'
			}
		},
		methods: {
			//订单明细
			getList() {
				let _this = this;
				_this.$http({
					url: '/addons/xilufitness/market_order/getOrderList',
					method: 'get'
				}).then(res => {
					_this.list = res.data.list.map((item, index) => {
						return {
							...item,
							// 假如接口没头像字段，手动补个
							avatar: item.avatar || '',
							pay_type: item.pay_type == 1 ? '余额支付' : item.pay_type == 2 ? '微信支付' : item
								.pay_type == 3 ? '积分支付' : item.pay_type == 4 ? '混合支付' : '',
							status: this.getOrderStatus(item.order_status),
							ebb: this.getEbbStatus(item.ebb_status)
						}
					})
				}).catch(error => {
					console.log('rechargeOrderError', error);
				})
			},
			getEbbStatus(status) {
				if (status == 0) {
					return ''
				} else if (status == 1) {
					return '申请退款中'
				} else if (status == 2) {
					return '同意退款'
				} else if (status == 3) {
					return '拒绝退款'
				}
			},
			getOrderStatus(status) {
				if (status == 0) {
					return '未支付'
				} else if (status == 1) {
					return '已支付'
				} else if (status == 2) {
					return '待揽件'
				} else if (status == 3) {
					return '已发货'
				} else if (status == 4) {
					return '已完成'
				}
			},
			toOrderDetail(id) {
				this.$api.navigate('../points_order_detail/points_order_detail?id=' + id);
			}
		},
		onLoad() {
			this.getList();
		},
		onReachBottom() {
			let list = this.list;
			let total_count = this.total_count;
			if (total_count > list.length) {
				this.page = this.page + 1;
				this.getList();
			}
		},
		onShareAppMessage() {}
	}
</script>

<style lang="scss" scoped>
	.status-express {
		font-size: 26rpx;
		color: #bbb;
		margin-top: 6rpx;
		display: flex;
		align-items: center;

		.status {
			font-weight: 500;

			&.paid {
				color: #41e05a;
			}

			&.unpaid {
				color: #ff7466;
			}
		}

		.express {
			margin-left: 36rpx;
			color: #ffd700;
		}
	}

	.xilu {
		&_item {
			display: flex;
			flex-direction: row;
			align-items: center;
			width: 700rpx;
			min-height: 155rpx;
			background: #fff;
			border-radius: 20rpx;
			margin-top: 30rpx;
			padding: 20rpx 30rpx 20rpx 20rpx;
			position: relative;
			box-sizing: border-box;

			.avatar {
				width: 90rpx;
				height: 90rpx;
				border-radius: 50%;
				background: #333;
				margin-right: 24rpx;
				flex-shrink: 0;
			}

			.right-content {
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: center;
				min-width: 0;

				.title {
					font-size: 32rpx;
					color: #333;
					font-weight: 500;
					line-height: 44rpx;
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: nowrap;
				}

				.subtitle {
					font-size: 28rpx;
					color: #999;
					line-height: 40rpx;
					margin-top: 8rpx;
				}

				.pay-info {
					margin-top: 14rpx;
					font-size: 32rpx;

					.pay-type,
					.pay-amount {
						color: #ffd700; // 金黄色
						font-weight: 600;
					}
				}
			}

			.arrow-box {
				position: absolute;
				right: 20rpx;
				bottom: 20rpx;

				.arrow-icon {
					font-size: 50rpx;
					color: #ffd700;
					font-weight: bold;
					display: inline-block;
					transform: scaleX(1.1);
				}
			}
		}
	}

	.yellow {
		color: #ffd700;
	}
</style>